package ExerciseThree;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import org.junit.Test;

public class IOTest {
	@Test
	public void test1()
	{
		FileReader fr=null;
		FileWriter fw=null;
		try
		{
			File file1 = new File("hellon.txt");
			File file2 = new File("hello3.txt");
			fr = new FileReader(file1);
			fw = new FileWriter(file2);
			char cubf[] = new char[5];
			int len;
			while((len = fr.read(cubf))!=-1)
			{
				fw.write(cubf,0,len);
			}
		}catch(Exception e)
		{
			e.printStackTrace();
		}finally
		{
			if(fr!=null)
			{
				try {
					fr.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if(fw!=null)
			{
				try {
					fw.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}

	@Test
	public void test2()
	{
		FileReader fr = null;
		FileWriter fw = null;
		try
		{
			File file1 = new File("D:\\JavaProject\\Exercise2\\src\\hello.txt");
			File file2 = new File("D:\\JavaProject\\Exercise2\\src\\hello2.txt");
			fr = new FileReader(file1);
			fw = new FileWriter(file2);
			char cubf[] = new char[5];
			int len;
			while((len = fr.read(cubf))!=-1)
			{
				fw.write(cubf,0,len);
			}
		}catch(Exception e)
		{
			e.printStackTrace();
		}finally
		{
			if(fr!=null)
			{
				try {
					fr.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if(fw!=null)
			{
				try {
					fw.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
}
